import {lazy, Suspense} from "react";
import {Navigate, Outlet, useRoutes} from "react-router-dom";
import Loading from '@/components/Loading'
import AuthComponent from "@/components/AuthComponent";
import Index from "@/pages/Index";
import {DatabaseOutlined, HomeOutlined,ClusterOutlined,MedicineBoxOutlined} from "@ant-design/icons";

const lazyLoading = function(path:any) {
    const Com = lazy(() => import('@/pages/'+ path))
    return <Suspense fallback={<Loading/>}><Com/></Suspense>
}
const routes = [
    {
        path: '/',
        element:(
            <AuthComponent>
                {/*{lazyLoading('Index')}*/}
                <Index/>
            </AuthComponent>
        ),
        children: [
            {
                label: '主页',
                path: '/',
                icon: <HomeOutlined />,
                element: lazyLoading('Home')
            },
            {
                label: '数据管理',
                path: '/cmn',
                icon: <DatabaseOutlined />,
                element: <Outlet/>,
                children: [
                    {
                        // index:true,
                        path: '/cmn',
                        isHide:true,//是否隐藏
                        element:<Navigate to={'dict'}/>
                    },
                    {
                        label: '数据字典',
                        path: '/cmn/dict',
                        element: lazyLoading('cmn/dict')
                    }
                ]
            },
            {
                label: '医院管理',
                path: "/hospital",
                icon: <MedicineBoxOutlined />,
                element: <Outlet/>,
                children: [
                    {
                        // index: true,
                        path: '/hospital',
                        isHide: true,
                        element: <Navigate to={'hospitalSet'}/>
                    },
                    {
                        // 医院设置
                        label:"医院设置",
                        path:"/hospital/hospitalSet",
                        element:lazyLoading("hospital/hospitalSet")
                    },
                    {
                        // 医院列表
                        label:"医院列表",
                        path:"/hospital/hospitalList",
                        element:lazyLoading("hospital/hospitalList")
                    },
                    {
                    //  /hospital/show/622574cc36a9ba1be763dad8
                        label:"医院详情",
                        isHide: true,//是否隐藏
                        path:"/hospital/show/:id",
                        element:lazyLoading("hospital/show")
                    },
                    {
                        //  /hospital/department/1000_0
                        label:"医院排班",
                        isHide: true,//是否隐藏
                        path:"/hospital/department/:hoscode",
                        element:lazyLoading("hospital/department")
                    }
                ]
            },
            {
                label: '商品管理',
                path: "/goods",
                icon: <ClusterOutlined />,
                element: <Outlet/>,
                children: [
                    {
                        // 品牌管理
                        label:"品牌管理",
                        path:"/goods/trademark",
                        element:lazyLoading("goods/trademark")
                    },
                    {
                        // 属性管理
                        label:"属性管理",
                        path:"/goods/attr",
                        element:lazyLoading("goods/attr")
                    },
                ]
            }
        ]
    },{
        path: 'login',
        element: lazyLoading('Login')
    },{
        path: '*',
        element: lazyLoading('NotFound')
    }
];
export const renderMenuItem = ()=> {
    return (routes.find(item => item.path === '/') as any).children;
}
export default function () {
    const renderRoutes = useRoutes(routes)
    return renderRoutes;
}
